import { createRouter, createWebHistory } from 'vue-router'

const gwVueTools = () =>
  import('@/components/gwVueTools.vue')
const gwAppVueTools = () => import('@/components/gwAppVueTools.vue')
const gwTextReadMoreView = () =>
  import('@/components/tools/views/gwTextReadMoreView.vue')
const gwAutoImageView = () => import('@/components/tools/views/gwAutoImageView.vue')
const gwTextBeforeImgView = () => import('@/components/tools/views/gwTextBeforeImgView.vue')
const gwTextareaCommontView = () => import('@/components/tools/views/gwTextareaCommontView.vue')
// 2. 定义一些路由
// 每个路由都需要映射到一个组件。
// 我们后面再讨论嵌套路由。
const routes = [
  { path: '/', redirect: '/gwVueTools' },
  {
    path: '/gwVueTools',
    name: 'gwVueTools',
    component: gwVueTools,

  },
  {
    path: '/gwAppVueTools',
    name: 'gwAppVueTools',
    component: gwAppVueTools
  },
  {
    path: '/gwTextReadMoreView',
    name: 'gwTextReadMoreView',
    component: gwTextReadMoreView
  },
  {
    path: '/gwAutoImageView',
    name: 'gwAutoImageView',
    component: gwAutoImageView
  },
  {
    path: '/gwTextBeforeImgView',
    name: 'gwTextBeforeImgView',
    component: gwTextBeforeImgView
  },
  {
    path: '/gwTextareaCommontView',
    name: 'gwTextareaCommontView',
    component: gwTextareaCommontView
  },
]

// 3. 创建路由实例并传递 `routes` 配置
// 你可以在这里输入更多的配置，但我们在这里
// 暂时保持简单
const router = createRouter({
  // 4. 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
  // mode: 'hash',
  history: createWebHistory(),
  routes, // `routes: routes` 的缩写
})

router.beforeEach((to, from, next) => {
  console.log('router.beforeEach-to', to.name)
  console.log('router.beforeEach-from', from.name)
  // 如果用户未能验证身份，则 `next` 会被调用两次
  next()
})

export default router